package net.zozoo.ioc;

import org.junit.jupiter.api.Test;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestUser {

    @Test
    public void testUser() throws BeansException {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");

        //根据id获取bean对象
        User user1 = (User) context.getBean("user");
        System.out.println("根据id获取对象："+user1);

        //根据类型获取
        User user2 = context.getBean(User.class);
        System.out.println("根据类型获取对象："+user2);

        //根据id和类型获取
        User user3 = context.getBean("user",User.class);
        System.out.println("根据id和类型获取对象："+user3);
    }
}
